package com.cmxh.mycloudnotes.controller;


import com.aliyun.oss.OSSClient;
import com.cmxh.mycloudnotes.util.Code01;
import com.cmxh.mycloudnotes.util.OSSUtil;
import com.cmxh.mycloudnotes.util.Result01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/result")
public class Result {
    @Autowired
   private OSSUtil ossUtil;



    @RequestMapping("/shangchuan")
    public Result01 xx(MultipartFile file) throws IOException {
        System.out.println("后端" + file);
        String originalFilename = file.getOriginalFilename();
        String newname = UUID.randomUUID().toString().substring(24) + "-" + originalFilename;
            OSSClient xx = new OSSClient(ossUtil.getUrl(), ossUtil.getId(), ossUtil.getMiyao());
        xx.putObject(ossUtil.getTong(), newname, file.getInputStream());
        String url1 = ossUtil.getUrl();
        String[] split = url1.split("//");
        String url = split[0] + "//" + ossUtil.getTong() + "." + split[1] + "/" + newname;
        return new Result01( Code01.UPLOAD_OK, url, "上传成功" );
    }
}